package main.java.com.web;

import main.java.com.entity.Category;
import main.java.com.service.CategoryTwoService;
import main.java.com.service.impl.CategoryTwoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//新增菜品控制层
@WebServlet("/adddish")
public class CategoryadddishServlvet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        String name = req.getParameter("dishname");
        String sort = req.getParameter("dishsort");
        Category category = new Category();
        category.setName(name);
        category.setSort(Integer.parseInt(sort));
        CategoryTwoService categoryService = new CategoryTwoServiceImpl();
        categoryService.adddish(category);
        resp.sendRedirect("/selectcategory");
    }
}
